#ifndef _NE_MIDI_PLAYER_H_
#define _NE_MIDI_PLAYER_H_

#include <audio/MIDI/MIDIEvent.h>
#include <audio/MIDI/MIDIOutDevice.h>
#include <audio/MIDI/MIDISequence.h>
#include <system/Timer.h>

namespace ne
{
    class NEAPI MIDIPlayer
    {
        public:
            MIDIPlayer();

            void setSequence(const MIDISequencePtr &pSequence);
            MIDISequencePtr getSequence() const;

            double getPlayedTime() const;
            double getPlayedTicks() const;

            bool isPlaying() const;

            bool play();
            bool stop();
            bool reset();

            // Microseconds
            bool tick();

            bool seek(const double ticks);

            bool apply(const double ticks);

            bool applyEvent(MIDIEvent *pEvent);

            bool sendEvent(const byte event, const byte channel, const byte parameter1, const byte parameter2);

            bool sendSysExEvent(const byte *buffer, const uint32_t length);

            ~MIDIPlayer();

        private:
            MIDIPlayer(const MIDIPlayer &player);

            MIDIPlayer& operator = (const MIDIPlayer &player);

        private:
            MIDIOutDevice *mpOutDevice;
            Timer *mpTimer;
            double mPlayedTime;
            double mPlayedTicks;
            bool mIsPlaying;

            MIDISequencePtr mpSequence;
            std::vector<MIDIEventListIterator> mEventListIterators;
    };
}

#endif
